//
//  KZDvdCell.m
//  xiaorizi
//
//  Created by kun on 15/10/23.
//  Copyright © 2015年 origin. All rights reserved.
//

#import "KZDvdCell.h"
#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "NSString+Frame.h"
@interface KZDvdCell ()
@property (weak, nonatomic) IBOutlet UIButton *imgButton;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelConstraint;

@end

@implementation KZDvdCell



//+(instancetype)newsCellWithTableView:(UITableView *)tableView
//{
//    NSString *className = NSStringFromClass([self class]);
//    UINib  *nib = [UINib nibWithNibName:className bundle:nil];
//    
//    [tableView registerNib:nib forCellReuseIdentifier:className];
//    
//    return [tableView dequeueReusableCellWithIdentifier:className];
//}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)setModel:(DvdModel *)model
{
    _model = model;
    
    //1 初始化数据
    
#warning 2 bug 点击图片时候 button会闪一下 需取消设置button高亮的状态
    [self.imgButton sd_setBackgroundImageWithURL:[NSURL URLWithString:model.img] forState:UIControlStateNormal];
    //初始化label
    self.titleLabel.text = model.titles;
    
    //更新约束
    CGFloat titleWidth = [model.titles widthWithFont:[UIFont systemFontOfSize:18]];
    self.titleLabelConstraint.constant = titleWidth;
    
    [self updateConstraintsIfNeeded];
}


//执行按钮点击事件
- (IBAction)imgButtonClicked:(id)sender {
    
    if(self.imgButtonBlock)
    {
        self.imgButtonBlock(self);
    }
}




@end
